package com.ssm.pre.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssm.pre.util.PageCount;
import com.ssm.pre.util.ToolUtil;
import com.ssm.pre.dao.WechatKeysDao;
import com.ssm.pre.service.WechatKeysService;
import com.ssm.util.object.InputObject;
import com.ssm.util.object.OutputObject;

@Service
public class WechatKeysServiceImpl implements WechatKeysService{
	
	@Autowired
	private WechatKeysDao wkDao;

	/**
	 * 查询关键字列表
	 */

	@Override
	public void queryWechatKeysList(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		List<Map<String, Object>> beans = wkDao.queryWechatKeysList(map);
		int page = Integer.parseInt(map.get("offset").toString())/Integer.parseInt(map.get("limit").toString());
		page++;
		List<Map<String, Object>> params = PageCount.page(beans, page, Integer.parseInt(map.get("limit").toString()));
		outputObject.setBeans(params);
		outputObject.settotal(beans.size());
	}

	/**
	 * 增加关键字
	 */
	@Override
	public void addWechatKeys(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		map.put("createId", inputObject.getLogParams().get("id"));
		map.put("createTime", ToolUtil.getTimeAndToString());
		wkDao.addWechatKeys(map);
		
	}
	
	/**
	 * 根据ID修改关键字
	 */
	@Override
	public void updateWechatKeys(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		Map<String, Object> keys = inputObject.getLogParams();
		map.put("createId", keys.get("id"));
		map.put("createTime", ToolUtil.getTimeAndToString());
		wkDao.updateWechatKeys(map);
		
	}

	/**
	 * 根据ID删除关键字
	 */
	@Override
	public void deleteWechatKeysById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		wkDao.deleteWechatKeysById(map);
	}

	/**
	 * 根据id查询关键字
	 * */
	@Override
	public void queryWechatKeysById(InputObject inputObject, OutputObject outputObject) throws Exception {
		Map<String, Object> map = inputObject.getParams();
		Map<String, Object> bean = wkDao.queryWechatKeysById(map);
		outputObject.setBean(bean);
	}

	
}
